#include<iostream>
#include<assert.h>
using namespace std;

namespace yangyi
{
	template<class T>
	struct list_node
	{
		T* _data;
		list_node<T>* _prev;
		list_node<T>* _next;

		list_node(const T& val = T())
			:_data(val)
			,_prev(nullptr)
			,_next(nullptr)
		{

		}
	};
	template <class T,class Ref,class Ptr>
	struct __list_iterator
	{
		typedef list_node<T> Node;
		typedef __list_iterator<T, T&, T*> iterator;
		typedef __list_iterator <T, const T&, const T*> const_iterator;

		Node* _node;
		__list_iterator(Node* node)
			:_node(node)
		{

		}

		bool operator==(iterator& it)const
		{
			return _node == it._node;
		}
		bool operator!=(iterator& it)const
		{
			return _node != it._node;
		}
		Ref operator*()
		{
			return _node->_data;
		}
		Ptr operator->()
		{
			return &(operator*());
		}
		iterator operator++()
		{
			_node = _node->_next;
			return *this;
		}
		iterator operator++(int)
		{
			iterator tmp(*this);
			_node = _node->_next;
			return tmp;
		}
		iterator operator--()
		{
			_node = _node->_prev;
		}
		iterator operator--(int)
		{
			iterator tmp = (*this);
			_node = _node->_prev;
			return tmp;
		}
	};
	template <class T>
	class list
	{
	public:
		typedef list_node<T> Node;
		typedef __list_iterator<T, T&, T*> iterator;
		typedef __list_iterator<T, const T&, const T*>const_iterator;

		typedef __reserve_iterator<T, T&, T*>reserve_iterator;
		const_iterator begin()const
		{
			return const_iterator(_head->_next);
		}
		const_iterator end()const
		{
			return const_iterator(_head);
		}
		empty_init()
		{
			Node* _head = new Node;
			_head->_next = _head;
			_head->_prev = _head;
		}
		list()
		{
			Node* _head = new Node;
			_head->_next = _head;
			_head->_prev = _head;
		}
		template <class InputIterator>
		list(InputIterator first,InputIterator last)
		{
			while (first != last)
			{
				push_back(*first);
				++_first;
			}
		}
		void swap(list<T> lt)
		{
			std::swap(_head, lt._head);
		}
		list(list<T>& lt)
		{
			empty_init()
			list<T> tmp(lt.begin(), lt.end());
			swap(tmp);
		}
		void clear()
		{
			iterator it = begin();
			while (it != end())
			{
				it = it.erase();
			}
		}
		~list()
		{
			clear();
			delete _head;
			_head = nullptr;
		}
		list<T>& operator==(list<T> lt)
		{
			swap(lt);
			return *this;
		}
		iterator begin()
		{
			return iterator(_head->_next);
		}
		iterator end()
		{
			return iterator(_head);
		}
		void push_back(const T& val=T())
		{
			insert(end(), val);
		}
		void push_front(const T& val=T())
		{
			insert(begin(), val);
		}
		void pop_back()
		{
			erase(end());
		}
		void pop_front()
		{
			erase(begin());
		}
		void swap(list<T>& lt)
		{
			std::swap(_head, lt._head);
		}
		vector(list<T>& lt)
		{
			list<T> tmp(lt.begin().lt.end());
			swap(tmp);
			return *this;
		}
		list<T>& operator=(list<T>& lt)
		{
			swap(lt);
			return *this;
		}
		list<T>& operator=(list<T>& lt)
		{
			swap(lt);
			return *this;
		}
		iterator insert(iterator pos, const T& val = T())
		{
			Node* cur = pos._node;
			Node* prev = cur->_prev;
			Node* newnode = new Node(x);
			prev->_next = cur;
			cur->_prev = prev;
			cur->_next = newnode;
			newnode->_prev = cur;
			return cur;
		}
		iterator erase(iterator pos)
		{
			Node* cur = pos._node;
			Node* prev = cur->_prev;
			Node* next = cur->_next;

			prev->_next = next;
			next->_prev = prev;
			delete cur;
			return next;
		}
		void clear()
		{
			iterator it = begin();
			while (it != end())
			{
				it = erase(it);
			}
		}
	private:
		Node* _head;
	};
}


